package com.sxy.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/**
 * @author 宋鑫宇
 * @version 1.0
 */
public class MybatisConfig {

    /**
     * SqlSessionFactory对象配置
     * @param dataSource
     * @return
     */
    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource){
        SqlSessionFactoryBean ssf = new SqlSessionFactoryBean();
        ssf.setTypeAliasesPackage("com.sxy.pojo");
        ssf.setDataSource(dataSource);
        return ssf;
    }

    /**
     * MapperScannerConfigurer（dao层）配置
     * mybatis自动代理
     * @return
     */
    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer(){
        MapperScannerConfigurer msc = new MapperScannerConfigurer();
        msc.setBasePackage("com.sxy.dao");
        return msc;
    }
}
